//
//  QLKStretchableImageCache.m
//  CloudsOutpatient
//
//  Created by 柴志勇 on 16/1/27.
//  Copyright © 2016年 HC. All rights reserved.
//

#import "QLKStretchableImageCache.h"


@implementation QLKStretchableImageCache
SYNTHESIZE_SINGLETON_FOR_CLASS(QLKStretchableImageCache)

- (id)init
{
  self = [super init];
  if (self)
  {
    _stretchableImages = [[NSMutableDictionary alloc] initWithCapacity:25];
    
  }
  return self;
}

- (void)dealloc
{
  [_stretchableImages release];
  [super dealloc];
}

- (UIImage*)imageNamed:(NSString*)imgName
          leftCapwidth:(NSInteger)leftCapWidth
          topCapHeight:(NSInteger)topCapHeight;
{
  NSString *strechKey = [NSString stringWithFormat:@"%@{%ld:%ld}", imgName, leftCapWidth, topCapHeight];
  
  UIImage* img = [_stretchableImages objectForKey:strechKey];
  
  if (!img){
    img = [UIImage imageNamed:imgName];
    img = [img stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
    
    if (img){
      [_stretchableImages setObject:img forKey:strechKey];
    }
  }
  
  return img;
}

@end
